using UnityEngine;

namespace Voodoo.Visual.UI.Button
{
	public class Shine : MonoBehaviour
	{
		public bool animated = true;

		public float timeOfTravel = 1f;

		private float currentTime;

		private float normalizedValue;

		public RectTransform mainRectTransform;

		private RectTransform rectTransform;

		private Vector3 startPosition;

		private Vector3 endPosition;

		private void Start()
		{
			rectTransform = GetComponent<RectTransform>();
			Vector3 localPosition = mainRectTransform.transform.localPosition;
			startPosition = new Vector3(localPosition.x - (mainRectTransform.rect.width / 2f + rectTransform.rect.width / 2f), localPosition.y, localPosition.z);
			base.transform.localPosition = startPosition;
			endPosition = new Vector3(localPosition.x + (mainRectTransform.rect.width / 2f + rectTransform.rect.width / 2f), localPosition.y, localPosition.z);
		}

		public void Animated(bool _isAnimated)
		{
			animated = _isAnimated;
			base.transform.localPosition = startPosition;
			currentTime = 0f;
		}

		private void Update()
		{
			if (animated)
			{
				if (currentTime <= timeOfTravel)
				{
					currentTime += Time.deltaTime;
					normalizedValue = currentTime / timeOfTravel;
					base.transform.localPosition = Vector3.Lerp(startPosition, endPosition, normalizedValue);
				}
				else
				{
					currentTime = 0f;
					base.transform.localPosition = startPosition;
				}
			}
		}
	}
}
